/**
 * Copyright (c) 2009 Koder Chen. All Rights Reserved.
 *
 * tool.h
 * The file defines the methods used to help the system. It includes
 * some functions to manipulate the memory's allocation, and free.
 *
 *  Author: chenfuhan
 * Created: 2009-6-1
 * Version: 1.0
 */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <memory.h>
#include <assert.h>

#include "tool.h"

i8_pt rsa_malloc_byte(u32_t bytes)
{
	assert(bytes>0);
	i8_pt t=(i8_pt)malloc(bytes);
	assert(t);
	memset(t, 0, bytes);
	return t;
}

u8_pt rsa_malloc_ubyte(u32_t bytes)
{
	assert(bytes>0);
	u8_pt t=(u8_pt)malloc(bytes);
	assert(t);
	memset(t, 0, bytes);
	return t;
}

i32_pt rsa_malloc_int(u32_t ints)
{
	assert(ints>0);
	i32_pt t=(i32_pt)malloc(ints*4);
	assert(t);
	memset(t, 0, ints*4);
	return t;
}

u32_pt rsa_malloc_uint(u32_t ints)
{
	assert(ints>0);
	u32_pt t=(u32_pt)malloc(ints*4);
	assert(t);
	memset(t, 0, ints*4);
	return t;
}

i32_t rsa_rand()
{
	LARGE_INTEGER seed;
	QueryPerformanceFrequency(&seed);
	QueryPerformanceCounter(&seed);
	srand(seed.QuadPart);
	return rand();
}
